home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2007 December / PCWKCD1207B.iso / Blogowanie poza sfera / Flock 0.9.1.3 stable / flock-0.9.1.3.en-US.win32.exe / flock / chrome / browser.jar / content / browser / openLocation.js < prev    next >
Text File  |  2006-07-18  |  4KB  |  131 lines

  1. //@line 41 "/cygdrive/K/tinderbuild/src/flock/mozilla/browser/base/content/openLocation.js"
  2.  
  3. var browser;
  4. var dialog = {};
  5. var pref = null;
  6. try {
  7.   pref = Components.classes["@mozilla.org/preferences-service;1"]
  8.                    .getService(Components.interfaces.nsIPrefBranch);
  9. } catch (ex) {
  10.   // not critical, remain silent
  11. }
  12.  
  13. function onLoad()
  14. {
  15.   dialog.input         = document.getElementById("dialog.input");
  16.   dialog.open          = document.documentElement.getButton("accept");
  17.   dialog.openWhereList = document.getElementById("openWhereList");
  18.   dialog.openTopWindow = document.getElementById("currentWindow");
  19.   dialog.bundle        = document.getElementById("openLocationBundle");
  20.  
  21.   if ("arguments" in window && window.arguments.length >= 1)
  22.     browser = window.arguments[0];
  23.    
  24.   dialog.openWhereList.selectedItem = dialog.openTopWindow;
  25.  
  26.   if (pref) {
  27.     try {
  28.       var useAutoFill = pref.getBoolPref("browser.urlbar.autoFill");
  29.       if (useAutoFill)
  30.         dialog.input.setAttribute("completedefaultindex", "true");
  31.     } catch (ex) {}
  32.  
  33.     try {
  34.       var value = pref.getIntPref("general.open_location.last_window_choice");
  35.       var element = dialog.openWhereList.getElementsByAttribute("value", value)[0];
  36.       if (element)
  37.         dialog.openWhereList.selectedItem = element;
  38.       dialog.input.value = pref.getComplexValue("general.open_location.last_url",
  39.                                                 Components.interfaces.nsISupportsString).data;
  40.     }
  41.     catch(ex) {
  42.     }
  43.     if (dialog.input.value)
  44.       dialog.input.select(); // XXX should probably be done automatically
  45.   }
  46.  
  47.   doEnabling();
  48. }
  49.  
  50. function doEnabling()
  51. {
  52.     dialog.open.disabled = !dialog.input.value;
  53. }
  54.  
  55. function open()
  56. {
  57.   var url;
  58.   var postData = {};
  59.   if (browser)
  60.     url = browser.getShortcutOrURI(dialog.input.value, postData);
  61.   else
  62.     url = dialog.input.value;
  63.  
  64.   try {
  65.     // Whichever target we use for the load, we allow third-party services to
  66.     // fixup the URI
  67.     switch (dialog.openWhereList.value) {
  68.       case "0":
  69.         browser.loadURI(url, null, postData.value, true);
  70.         break;
  71.       case "1":
  72.         window.opener.delayedOpenWindow(getBrowserURL(), "all,dialog=no",
  73.                                         url, postData.value, null, null, true);
  74.         break;
  75.       case "3":
  76.         if (browser.getBrowser && browser.getBrowser().localName == "tabbrowser")
  77.           browser.delayedOpenTab(url, null, null, postData.value, true);
  78.         else
  79.           browser.loadURI(url, null, postData.value, true); // Just do a normal load.
  80.         break;
  81.     }
  82.   }
  83.   catch(exception) {
  84.   }
  85.  
  86.   if (pref) {
  87.     var str = Components.classes["@mozilla.org/supports-string;1"]
  88.                         .createInstance(Components.interfaces.nsISupportsString);
  89.     str.data = dialog.input.value;
  90.     pref.setComplexValue("general.open_location.last_url",
  91.                          Components.interfaces.nsISupportsString, str);
  92.     pref.setIntPref("general.open_location.last_window_choice", dialog.openWhereList.value);
  93.   }
  94.  
  95.   // Delay closing slightly to avoid timing bug on Linux.
  96.   window.close();
  97.   return false;
  98. }
  99.  
  100. function createInstance(contractid, iidName)
  101. {
  102.   var iid = Components.interfaces[iidName];
  103.   return Components.classes[contractid].createInstance(iid);
  104. }
  105.  
  106. const nsIFilePicker = Components.interfaces.nsIFilePicker;
  107. function onChooseFile()
  108. {
  109.   try {
  110.     var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(nsIFilePicker);
  111.     fp.init(window, dialog.bundle.getString("chooseFileDialogTitle"), nsIFilePicker.modeOpen);
  112.     fp.appendFilters(nsIFilePicker.filterHTML | nsIFilePicker.filterText |
  113.                      nsIFilePicker.filterAll | nsIFilePicker.filterImages | nsIFilePicker.filterXML);
  114.  
  115.     if (fp.show() == nsIFilePicker.returnOK && fp.fileURL.spec && fp.fileURL.spec.length > 0)
  116.       dialog.input.value = fp.fileURL.spec;
  117.   }
  118.   catch(ex) {
  119.   }
  120.   doEnabling();
  121. }
  122.  
  123. function useUBHistoryItem(aMenuItem)
  124. {
  125.   var urlbar = document.getElementById("dialog.input");
  126.   urlbar.value = aMenuItem.getAttribute("label");
  127.   urlbar.focus();
  128.   doEnabling();
  129. }
  130.  
  131.